home *** CD-ROM | disk | FTP | other *** search
/ Aminet 45 / Aminet 45 (2001)(GTI - Schatztruhe)[!][Oct 2001].iso / Aminet / game / role / ldmud-3.2-bin.lha / mud / doc / efun / call_other < prev    next >
Text File  |  2001-04-23  |  4KB  |  90 lines

  1. SYNOPSIS
  2.         unknown call_other(object ob, string fun, mixed arg, ...)
  3.         unknown call_other(object *ob, string fun, mixed arg, ...)
  4.  
  5.         ob->fun (mixed arg, ...)
  6.         ob->"fun" (mixed arg, ...)
  7.         ob->(fun) (mixed arg, ...)
  8.  
  9. DESCRIPTION
  10.         Call a member function <fun> in another object <ob> with an
  11.         the argument(s) <arg...>. Result is the value returned from
  12.         the called function (or 0 for non-existing or void functions).
  13.  
  14.         If <ob> is given as an array of objects, the function is called
  15.         with the same arguments in all the given objects. The single
  16.         results are collected in an array and yield the final result.
  17.         Array elements can be objects or the names of existing objects;
  18.         destructed objects and 0s will yield a '0' as result, but don't
  19.         cause an error.
  20.  
  21.         The object(s) can be given directly or via a string (i.e. its
  22.         object_name). If it is given by a string and the object does not
  23.         exist yet, it will be loaded.
  24.         
  25.         ob->fun(args) and "ob_name"->fun(args) is equivalent to
  26.         call_other(ob, "fun", args). Nowadays the ob_name string can
  27.         also be a variable.
  28.  
  29.         ob->fun(args) and ob->"fun"(args) are equivalent to
  30.         call_other(ob, "fun", args). ob->(fun)(args) are equivalent
  31.         to call_other(ob, fun, args) where fun is a runtime expression
  32.         returning the function name.
  33.  
  34.         If ob does not define a publicly accessible function of the
  35.         specified name, call_other() will return 0, which is
  36.         indistinguishable from a function returning 0. "publicly
  37.         accessible" means "public" when calling other objects, and
  38.         "public" or "static" when calling this_object(). "private"
  39.         and "protected" function can never be called with call_other().
  40.  
  41.         The return type of call_other() is 'any' be default. However,
  42.         if your LPC code uses #pragma strict_types, the return type is
  43.         'unknown', and the result of call_other() must be casted to
  44.         the appropriate type before you can use it for anything.
  45.  
  46. EXAMPLES
  47.  
  48.         // All the following statements call the lfun QueryProp()
  49.         // in the current player with the argument P_SHORT.
  50.         string str, fun;
  51.  
  52.         str = (string)call_other(this_player(), "QueryProp", P_SHORT);
  53.         fun = "QueryProp";
  54.         str = (string)call_other(this_player(), fun, P_SHORT);
  55.  
  56.         str = (string)this_player()->QueryProp(P_SHORT);
  57.         str = (string)this_player()->"QueryProp"(P_SHORT);
  58.         fun = "QueryProp";
  59.         str = (string)this_player()->(fun)(P_SHORT);
  60.         
  61.         You have to do explicit type casting because of the unknown
  62.         return type, if you have set #pragma strict_types.
  63.         
  64.         // This statement calls the lfun short() in all interactive users
  65.         // and stores the collected results in a variable.
  66.         string * s;
  67.  
  68.         s = (string *)users()->short();
  69.  
  70.  
  71.         !Compat: call_other("/users/luser/thing", "???", 0);
  72.          Compat: call_other("users/luser/thing", "???", 0);
  73.         
  74.         This looks a bit weird but it was used very often to just load
  75.         the object by calling a not existing function like "???".
  76.         Fortunately nowadays there is an efun load_object() for this
  77.         purpose.
  78.  
  79. HISTORY
  80.         In LDMud 3.2.8 the following improvements were made:
  81.          - the forms x->"y"() and x->(y)() are recognized;
  82.          - the form x->y() no longer clashes with a local variable also
  83.            called "y";
  84.          - a simul_efun call_other() also catches ->() calls.
  85.          - call_other can be applied on arrays of objects.
  86.  
  87. SEE ALSO
  88.         function_exists(E), call_resolved(E), create(A), pragma(LPC),
  89.         extern_call(E), functions(LPC)
  90.